<template>
  <view class="report_box">
    <view class="item-box">
      <view class="title-box"> 举报描述<text>*</text> </view>
      <view class="textarea-box">
        <textarea
          maxlength="200"
          placeholder="请描述作品中存在的问题，如:让你感到不适的画面或其他未提及的违规内容"
          v-model="content"
        />
        <view class="num">{{ content.length }}/200字</view>
      </view>
    </view>
    <view class="item-box">
      <view class="title-box">
        图片证据<text></text> <text class="des"> ( 上传图片（最多上传9张）)</text>
      </view>

      <view class="upload-img flex1 mar-t-20">
        <view class="img_list" @click="openAuth" v-show="imgList.length < 9">
          <u-icon name="photo-fill" color="#AAAAAA" size="60rpx"></u-icon>
          <view>上传照片</view>
        </view>
        <view class="img_list" v-for="(item, index) in imgList" :key="index">
          <view class="img_list_del" @click="toDelete(index)"
            ><u-icon name="close-circle-fill" color="#FFF" size="40rpx"></u-icon
          ></view>
          <image :src="item" mode="aspectFill"></image>
        </view>
      </view>
    </view>
    <view class="sub-fixed-box">
      <view class="sub-btn" @click="bindSub">提交</view>
    </view>
  </view>

  <h-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></h-authpup>
</template>

<script setup>
import { ref, reactive, nextTick } from 'vue'
import { onLoad, onPullDownRefresh, onReachBottom, onShow } from '@dcloudio/uni-app'
import { uploadApi } from '@/utils/upLoad'
import {  reportApi} from '@/api/social'
const authpup = ref(null)

function openAuth() {
  nextTick(() => {
    authpup.value.open()
  })
}
function changeAuth() {
  uni.chooseImage({
    count: 9,
    sizeType: ['compressed'],
    success: async (e) => {
      e.tempFilePaths.forEach(async (item) => {
        const res = await uploadApi(item)
        imgList.value.push(res)
      })
    },
  })
}

function toDelete(i) {
  imgList.value.splice(i, 1)
}

var imgList = ref([])
var content = ref('')
var post_id = ref('')
var post_type = ref('')
onLoad(({ id, type }) => {
  post_id.value = id
  post_type.value = type
})

async function bindSub() {
  if (!content.value) {
    uni.showToast({
      title: '请说明举报描述！',
      icon: 'none',
    })
    return false
  }
  if (imgList.value.length == 10) {
    uni.showToast({
      title: '最多上传图片',
      icon: 'none',
    })
    return false
  }
  var res = await reportApi({
    type: post_type.value, //1= 动态2=kepu
    post_id: post_id.value,
    content: content.value,
    images: imgList.value.toString(),
  })


  if(res.code==200){
    setTimeout(function () {
      uni.navigateBack({
        delta: 1,
      })
    }, 2000)
  }
  uni.showToast({
    title: res.message,
    icon: 'none',
  })
}
</script>

<style lang="scss" scoped>
.upload-img {
  margin-top: 30rpx;
  margin-bottom: 30rpx;
  overflow: hidden;

  .img_list {
    width: 200rpx;
    height: 200rpx;
    float: left;
    position: relative;
    border-radius: 10rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #F5F6F8;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 26rpx;
    color: #AAAAAA;
    image {
      width: 100%;
      height: 100%;
      border-radius: 10rpx;
    }

    .img_list_del {
      position: absolute;
      top: 0;
      right: 0;
      width: 40rpx;
      height: 40rpx;
      border-radius: 50%;
      z-index: 10;
    }
  }
}

page {
  width: 100%;
  background-color: #F5F6F8;
}

.report_box {
  margin: 24rpx;

  .sub-fixed-box {
    position: fixed;
    background-color: #fff;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20rpx 28rpx;
    padding-bottom: calc(20rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
    padding-bottom: calc(20rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
    .sub-btn {
      height: 90rpx;
      line-height: 90rpx;
      background-color: #00C1B9;
      width: 694rpx;
      color: #fff;
      font-size: 32rpx;
      text-align: center;
      border-radius: 45rpx;
    }
  }

  .item-box {
    margin-bottom: 20rpx;
    background-color: #fff;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 20rpx;

    .title-box {
      font-size: 32rpx;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      color: #202020;

      text {
        margin-left: 10rpx;
        color: red;
      }

      .des {
        margin-left: 10rpx;
        font-size: 22rpx;
        color: #999999;
      }
    }

    .picker {
      margin-top: 30rpx;

      .picker-box {
        position: relative;
        width: 100%;
        height: 90rpx;
        line-height: 90rpx;
        padding: 0 30rpx;
        background-color: #f5f5f5;
        border-radius: 10rpx;

        .iconfont {
          position: absolute;
          right: 30rpx;
          top: 50%;
          transform: translateY(-50%);
          font-size: 22rpx;
          color: var(--view-theme);
        }
      }
    }

    .textarea-box {
      background: #fff;
      border-radius: 10rpx;
      margin-top: 10rpx;

      textarea {
        width: 100%;
        height: 250rpx;
        font-size: 26rpx;
        line-height: 1.5;
      }

      .num {
        color: #999;
        text-align: right;
        padding: 20rpx;
      }
    }

    .input-box {
      input {
        display: block;
        width: 100%;
        height: 90rpx;
        margin-top: 20rpx;
        padding-left: 20rpx;
        background: #f5f5f5;
        border-radius: 10rpx;
        font-size: 28rpx;
      }
    }

    .link {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-top: 20rpx;

      .iconfont {
        margin-top: 6rpx;
        font-size: 22rpx;
      }
    }
  }
}
</style>
